﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FEP
{
    public class FepCom
    {
        public class StatusPack
        {
            public string FQDN;
            public string CurrentUser;
            public AntimalwareHealthStatus HealthStatus;
            public AntimalwareInfectionStatus InfectionStatus;
            public DateTime CurrentDateTime;
            public ActionPack LastAction = new ActionPack();
            public bool LastActionSucceeded;
            public bool ActionRunning;
            public string ActionResponseDataXML;
            public string CurrentPolicyXML;
            public StatusPack(string Computer)
            {
                RegistryHelper rh = new RegistryHelper();
                FQDN = Helper.GetFQDN();
                CurrentUser = Environment.UserName;
                HealthStatus = AntimalwareHealthStatus.GetCurrent(Computer);
                InfectionStatus = AntimalwareInfectionStatus.GetCurrent(Computer);
                CurrentDateTime = DateTime.Now;
                CurrentPolicyXML = rh.PolicyXML;

            }
            public StatusPack()
            {
            }
        }
        public class CommandPack
        {
            public int PollingInterval;
            public ActionPack Action = new ActionPack();
            public string PolicyXML;

        }
        public class ActionPack
        {

            public ActionType TypeOfAction = ActionType.Nothing;
            public string ActionDataXML;
        }
        public enum ActionType
        {
            Nothing = 0,
            FullScan = 1,
            QuickScan = 2,
            CustomSingleFileScan = 3,
            UpdateDefinitions = 4,
            RemoveDefinitions = 5,
            RemoveAllDynamicSignatures = 6,
            AddDynamicSignature = 7,
            ListAllDynamicSignatures = 8,
            RemoveDynamicSignatures = 9,
            Trace = 10,
            GetFiles = 11,
            RedirectToNewHost = 12,
            UpdateFEPClientService = 13,
            UpdateFEPClient = 14

        }
        #region Web Service Proxy

        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        [System.Web.Services.WebServiceBindingAttribute(Name = "Service1Soap", Namespace = "http://inacom-sby.net/FEPMGR/")]
        public partial class MGRService : System.Web.Services.Protocols.SoapHttpClientProtocol
        {

            private System.Threading.SendOrPostCallback PollOperationCompleted;

            /// <remarks/>
            public MGRService(string Host)
            {
                //"http://localhost:2013/MGRService.asmx"
                this.Url = Host;
            }

            /// <remarks/>
            public event PollCompletedEventHandler PollCompleted;

            /// <remarks/>
            [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://inacom-sby.net/FEPMGR/Poll", RequestNamespace = "http://inacom-sby.net/FEPMGR/", ResponseNamespace = "http://inacom-sby.net/FEPMGR/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
            public FEP.FepCom.CommandPack Poll(FEP.FepCom.StatusPack incoming)
            {

                object[] results = this.Invoke("Poll", new object[] {
                    incoming});
                return ((FEP.FepCom.CommandPack)(results[0]));
            }

            /// <remarks/>
            public System.IAsyncResult BeginPoll(FEP.FepCom.StatusPack incoming, System.AsyncCallback callback, object asyncState)
            {
                return this.BeginInvoke("Poll", new object[] {
                    incoming}, callback, asyncState);
            }

            /// <remarks/>
            public FEP.FepCom.CommandPack EndPoll(System.IAsyncResult asyncResult)
            {
                object[] results = this.EndInvoke(asyncResult);
                return ((FEP.FepCom.CommandPack)(results[0]));
            }

            /// <remarks/>
            public void PollAsync(FEP.FepCom.StatusPack incoming)
            {
                this.PollAsync(incoming, null);
            }

            /// <remarks/>
            public void PollAsync(FEP.FepCom.StatusPack incoming, object userState)
            {
                if ((this.PollOperationCompleted == null))
                {
                    this.PollOperationCompleted = new System.Threading.SendOrPostCallback(this.OnPollOperationCompleted);
                }
                this.InvokeAsync("Poll", new object[] {
                    incoming}, this.PollOperationCompleted, userState);
            }

            private void OnPollOperationCompleted(object arg)
            {
                if ((this.PollCompleted != null))
                {
                    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                    this.PollCompleted(this, new PollCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
                }
            }

            /// <remarks/>
            public new void CancelAsync(object userState)
            {
                base.CancelAsync(userState);
            }
        }


        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
        public delegate void PollCompletedEventHandler(object sender, PollCompletedEventArgs e);

        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        public partial class PollCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
        {

            private object[] results;

            internal PollCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
                base(exception, cancelled, userState)
            {
                this.results = results;
            }

            /// <remarks/>
            public FEP.FepCom.CommandPack Result
            {
                get
                {
                    this.RaiseExceptionIfNecessary();
                    return ((FEP.FepCom.CommandPack)(this.results[0]));
                }
            }
        }
        #endregion
    }
   
}
